package com.dc.refactoring._2_在对象之间搬移特性._1_MoveMethod.oldObject;

/**
 * Description: 搬移函数_账户
 * @author: gdc
 * @date: 2020/11/14
 * @version 1.0
 */
public class Account {
    /**
     * 账户类型
     */
    private AccountType accountType;
    /**
     * 透支天数
     */
    private int daysOverdrawn;

    /**
     * 透支金额计算规则
     */
    public double overdraftCharge() {
        double result;
        if (accountType.isPremium()) {
            result = 10;
            if (daysOverdrawn > 7) {
                result += (daysOverdrawn - 7) * 0.85;
            }
        } else {
            result = daysOverdrawn * 1.75;
        }
        return result;
    }

    /**
     * 计算手续费，没有透支时为4.5，有透支时=4.5+透支金额
     */
    public double bankCharge() {
        double result = 4.5;
        if (daysOverdrawn > 0) {
            result += overdraftCharge();
        }
        return result;
    }
}
